﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;

namespace Speedy
{
    public partial class FrmTasarim : XtraForm
    {
        private string path = "";
        private DevExpress.Utils.WaitDialogForm dlg = null;

        public FrmTasarim()
        {
            InitializeComponent();
        }

        private void FrmTasarim_FormClosing(object sender, FormClosingEventArgs e)
        {

            {
                DialogResult Message = MessageBox.Show("Çıkmak İstediğinize Emin Misiniz ?", "UYARI", MessageBoxButtons.YesNo);
                if (Message == DialogResult.Yes)
                {
                    StreamWriter sw = new StreamWriter(path + "\\tasarim.ini", false);
                    for (int i = 1; i <= 66; i++)
                    {
                        sw.WriteLine(C1FlexGrid1[i, 0]);
                        sw.WriteLine(C1FlexGrid1[i, 1]);
                        sw.WriteLine(C1FlexGrid1[i, 2]);
                        sw.WriteLine(C1FlexGrid1[i, 3]);
                    }
                    sw.Close();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }


        private string tasarimIsmi(string pth)
        {
            FileInfo fin = new FileInfo(pth);
            if (fin.Extension == ".tsrm")
                return fin.Name.Replace(fin.Extension, "");
            else
                return string.Empty;
        }

        private void FrmTasarim_Load(object sender, EventArgs e)
        {
            {
                path = Application.StartupPath + "\\Tasarim";

                if (Directory.Exists(path))
                {
                    DirectoryInfo pth = new DirectoryInfo(path);
                    //klasordeki tum dosyalar okunuyor
                    foreach (FileInfo fName in pth.GetFiles())
                    {
                        if (!string.IsNullOrEmpty(tasarimIsmi(fName.Name)))
                        {
                            tsrm_file.Properties.Items.Add(tasarimIsmi(fName.Name));
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(path);
                }
                if (File.Exists(path + "\\tasarim.ini"))
                {
                    StreamReader sr = new StreamReader(path + "\\tasarim.ini");
                    for (int i = 1; i <= 66; i++)
                    {
                        C1FlexGrid1[i, 0] = sr.ReadLine();
                        C1FlexGrid1[i, 1] = sr.ReadLine();
                        C1FlexGrid1[i, 2] = sr.ReadLine();
                        C1FlexGrid1[i, 3] = sr.ReadLine();
                    }
                    sr.Close();
                }
                else
                {
                    sablon();
                }
                C1.Win.C1FlexGrid.CellStyle NewStyle = default(C1.Win.C1FlexGrid.CellStyle);
                NewStyle = C1FlexGrid1.Styles.Add("NewStyleX");
                NewStyle.BackColor = Color.Khaki;
                C1.Win.C1FlexGrid.CellStyle NewStyle2 = default(C1.Win.C1FlexGrid.CellStyle);
                NewStyle2 = C1FlexGrid1.Styles.Add("NewStyleXY");
                NewStyle2.BackColor = Color.Khaki;
                NewStyle2.DataType = typeof(Int32);
                C1.Win.C1FlexGrid.CellStyle NewStyle3 = default(C1.Win.C1FlexGrid.CellStyle);
                NewStyle3 = C1FlexGrid1.Styles.Add("NewStyleXZ");
                NewStyle3.ComboList = "COM1|COM2|COM3|COM4|COM5|COM6|COM7|COM8|COM9|COM10|LPT1|LPT2|LPT3|LPT4|LPT5";
                C1FlexGrid1.SetCellStyle(1, 1, NewStyle3);
                for (int i = 30; i <= 46; i++)
                {
                    C1FlexGrid1.SetCellStyle(i, 0, NewStyle);
                    C1FlexGrid1.SetCellStyle(i, 1, NewStyle);
                    C1FlexGrid1.SetCellStyle(i, 2, NewStyle2);
                    C1FlexGrid1.SetCellStyle(i, 3, NewStyle);
                }
                C1FlexGrid1.AutoSizeCols();
            }
            tsrm_file.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
        }
        private void sablon()
        {
            C1FlexGrid1[1, 0] = "Yazıcı Portu";
            C1FlexGrid1[1, 1] = "COM4";
            C1FlexGrid1[1, 2] = "";

            C1FlexGrid1[2, 0] = "Fatura Satır Sayısı";
            C1FlexGrid1[2, 1] = "66";
            C1FlexGrid1[2, 2] = "";

            C1FlexGrid1[3, 0] = "Hareket Satır Sayısı";
            C1FlexGrid1[3, 1] = "33";
            C1FlexGrid1[3, 2] = "";

            C1FlexGrid1[4, 0] = "Fatura Genişliği";
            C1FlexGrid1[4, 1] = "80";
            C1FlexGrid1[4, 2] = "";

            //üst bilgiler
            C1FlexGrid1[5, 0] = "Firma Kodu";
            C1FlexGrid1[5, 1] = "";
            C1FlexGrid1[5, 2] = "";

            C1FlexGrid1[6, 0] = "Firma Ünvanı";
            C1FlexGrid1[6, 1] = "3";
            C1FlexGrid1[6, 2] = "13";

            C1FlexGrid1[7, 0] = "Adres 1. Satır";
            C1FlexGrid1[7, 1] = "3";
            C1FlexGrid1[7, 2] = "15";

            C1FlexGrid1[8, 0] = "Adres 2. Satır";
            C1FlexGrid1[8, 1] = "3";
            C1FlexGrid1[8, 2] = "16";

            C1FlexGrid1[9, 0] = "Adres 3. Satır";
            C1FlexGrid1[9, 1] = "3";
            C1FlexGrid1[9, 2] = "17";

            C1FlexGrid1[10, 0] = "Vergi Dairesi";
            C1FlexGrid1[10, 1] = "61";
            C1FlexGrid1[10, 2] = "17";

            C1FlexGrid1[11, 0] = "Vergi No";
            C1FlexGrid1[11, 1] = "61";
            C1FlexGrid1[11, 2] = "19";

            C1FlexGrid1[12, 0] = "Fatura Tarihi";
            C1FlexGrid1[12, 1] = "61";
            C1FlexGrid1[12, 2] = "13";

            C1FlexGrid1[13, 0] = "Fatura No";
            C1FlexGrid1[13, 1] = "61";
            C1FlexGrid1[13, 2] = "15";

            C1FlexGrid1[14, 0] = "Depo";
            C1FlexGrid1[14, 1] = "";
            C1FlexGrid1[14, 2] = "";

            C1FlexGrid1[15, 0] = "Açık/Kapalı";
            C1FlexGrid1[15, 1] = "";
            C1FlexGrid1[15, 2] = "";

            C1FlexGrid1[16, 0] = "Ödeme Tarihi";
            C1FlexGrid1[16, 1] = "";
            C1FlexGrid1[16, 2] = "";

            C1FlexGrid1[17, 0] = "Fatura Basım Saati";
            C1FlexGrid1[17, 1] = "";
            C1FlexGrid1[17, 2] = "";

            C1FlexGrid1[18, 0] = "Fatura Notu";
            C1FlexGrid1[18, 1] = "";
            C1FlexGrid1[18, 2] = "";

            C1FlexGrid1[19, 0] = "Sevk Tarihi";
            C1FlexGrid1[19, 1] = "";
            C1FlexGrid1[19, 2] = "";

            for (int i = 20; i < 30; i++)
            {
                C1FlexGrid1[i, 0] = "Özel Alan" + (i - 19).ToString();
                C1FlexGrid1[i, 1] = "";
                C1FlexGrid1[i, 2] = "";
            }


            //stok detayları
            C1FlexGrid1[30, 0] = "Sıra No";
            C1FlexGrid1[30, 1] = "";
            C1FlexGrid1[30, 2] = "23";

            C1FlexGrid1[31, 0] = "Stok Kodu";
            C1FlexGrid1[31, 1] = "";
            C1FlexGrid1[31, 2] = "23";

            C1FlexGrid1[32, 0] = "Barkodu";
            C1FlexGrid1[32, 1] = "";
            C1FlexGrid1[32, 2] = "23";

            C1FlexGrid1[33, 0] = "Ürün Adı";
            C1FlexGrid1[33, 1] = "12";
            C1FlexGrid1[33, 2] = "23";

            C1FlexGrid1[34, 0] = "Miktar";
            C1FlexGrid1[34, 1] = "1";
            C1FlexGrid1[34, 2] = "23";

            C1FlexGrid1[35, 0] = "Birim";
            C1FlexGrid1[35, 1] = "";
            C1FlexGrid1[35, 2] = "23";

            C1FlexGrid1[36, 0] = "Kdv";
            C1FlexGrid1[36, 1] = "";
            C1FlexGrid1[36, 2] = "23";

            C1FlexGrid1[37, 0] = "İskonto Tutar";
            C1FlexGrid1[37, 1] = "";
            C1FlexGrid1[37, 2] = "23";

            C1FlexGrid1[38, 0] = "İskonto Oran";
            C1FlexGrid1[38, 1] = "";
            C1FlexGrid1[38, 2] = "";

            C1FlexGrid1[39, 0] = "Kampanya";
            C1FlexGrid1[39, 1] = "";
            C1FlexGrid1[39, 2] = "23";

            C1FlexGrid1[40, 0] = "Satış Fiyat";
            C1FlexGrid1[40, 1] = "48";
            C1FlexGrid1[40, 2] = "23";

            C1FlexGrid1[41, 0] = "Tutar";
            C1FlexGrid1[41, 1] = "61";
            C1FlexGrid1[41, 2] = "23";

            C1FlexGrid1[42, 0] = "İsk1";
            C1FlexGrid1[42, 1] = "";
            C1FlexGrid1[42, 2] = "";

            C1FlexGrid1[43, 0] = "İsk2";
            C1FlexGrid1[43, 1] = "";
            C1FlexGrid1[43, 2] = "";

            C1FlexGrid1[44, 0] = "İsk3";
            C1FlexGrid1[44, 1] = "";
            C1FlexGrid1[44, 2] = "";

            C1FlexGrid1[45, 0] = "İsk4";
            C1FlexGrid1[45, 1] = "";
            C1FlexGrid1[45, 2] = "";

            C1FlexGrid1[46, 0] = "İsk5";
            C1FlexGrid1[46, 1] = "";
            C1FlexGrid1[46, 2] = "";

            //alt bilgiler
            C1FlexGrid1[47, 0] = "Toplam";
            C1FlexGrid1[47, 1] = "61";
            C1FlexGrid1[47, 2] = "A1";

            C1FlexGrid1[48, 0] = "İskonto";
            C1FlexGrid1[48, 1] = "61";
            C1FlexGrid1[48, 2] = "A3";

            C1FlexGrid1[49, 0] = "Ara Toplam";
            C1FlexGrid1[49, 1] = "61";
            C1FlexGrid1[49, 2] = "A4";

            C1FlexGrid1[50, 0] = "Kdv Toplamları";
            C1FlexGrid1[50, 1] = "24";
            C1FlexGrid1[50, 2] = "A1";

            C1FlexGrid1[51, 0] = "Kdv Toplam";
            C1FlexGrid1[51, 1] = "61";
            C1FlexGrid1[51, 2] = "A5";

            C1FlexGrid1[52, 0] = "Genel Toplam";
            C1FlexGrid1[52, 1] = "61";
            C1FlexGrid1[52, 2] = "A6";

            C1FlexGrid1[53, 0] = "Genel Toplam (Yazı İle)";
            C1FlexGrid1[53, 1] = "3";
            C1FlexGrid1[53, 2] = "A7";

            C1FlexGrid1[54, 0] = "Ödeme Planı";
            C1FlexGrid1[54, 1] = "";
            C1FlexGrid1[54, 2] = "";

            C1FlexGrid1[55, 0] = "Eski Bakiye";
            C1FlexGrid1[55, 1] = "";
            C1FlexGrid1[55, 2] = "";

            C1FlexGrid1[56, 0] = "Yeni Bakiye";
            C1FlexGrid1[56, 1] = "";
            C1FlexGrid1[56, 2] = "";

            for (int i = 57; i < 67; i++)
            {
                C1FlexGrid1[i, 0] = "Özel Alan" + (i - 56 + 10).ToString();
                C1FlexGrid1[i, 1] = "";
                C1FlexGrid1[i, 2] = "";
            }

        }

        private void btn_yeni_Click(object sender, EventArgs e)
        {
            yeniTasarim(path + "\\tasarim.ini");
            tsrm_file.Text = "";
        }
        private void yeniTasarim(string pth)
        {
            C1FlexGrid1.Clear(C1.Win.C1FlexGrid.ClearFlags.Content);
            C1FlexGrid1.Cols[0].Caption = "Alanlar";
            C1FlexGrid1.Cols[1].Caption = "Sütun";
            C1FlexGrid1.Cols[2].Caption = "Satır";
            C1FlexGrid1.Cols[3].Caption = "Uzunluk";

            if (File.Exists(pth))
            {
                StreamReader sr = new StreamReader(pth);
                for (int i = 1; i <= 66; i++)
                {
                    C1FlexGrid1[i, 0] = sr.ReadLine();
                    C1FlexGrid1[i, 1] = sr.ReadLine();
                    C1FlexGrid1[i, 2] = sr.ReadLine();
                    C1FlexGrid1[i, 3] = sr.ReadLine();
                }
                sr.Close();
            }
            else
            {
                sablon();
            }
            C1FlexGrid1.Focus();
            C1FlexGrid1.Select(1, 0);
            C1FlexGrid1.AutoSizeCols();
        }

        private void btn_sil_Click(object sender, EventArgs e)
        {
            {
                if (!string.IsNullOrEmpty(tsrm_file.Text))
                {
                    DialogResult Message = MessageBox.Show("Silmek İstediğinize Emin Misiniz ?", "UYARI", MessageBoxButtons.YesNo);
                    if (Message == DialogResult.Yes)
                    {
                        string fpath = path + "\\" + tsrm_file.Text + ".tsrm";
                        File.Delete(fpath);
                        DirectoryInfo pth = new DirectoryInfo(path);
                        //klasordeki tum dosyalar okunuyor
                        tsrm_file.Properties.Items.Clear();
                        foreach (FileInfo fName in pth.GetFiles())
                        {
                            if (!string.IsNullOrEmpty(tasarimIsmi(fName.Name)))
                            {
                                tsrm_file.Properties.Items.Add(tasarimIsmi(fName.Name));
                            }
                        }
                        yeniTasarim(path + "\\tasarim.ini");
                        tsrm_file.Text = "";
                    }
                }
            }
        }

        private void btn_kaydet_Click(object sender, EventArgs e)
        {
            {
                if (!string.IsNullOrEmpty(tsrm_file.Text))
                {
                    DialogResult Message = MessageBox.Show("Kaydetmek İstediğinize Emin Misiniz ?", "UYARI", MessageBoxButtons.YesNo);
                    if (Message == DialogResult.Yes)
                    {
                        StreamWriter sw = new StreamWriter(path + "\\" + tsrm_file.Text + ".tsrm", false);
                        for (int i = 1; i <= 66; i++)
                        {
                            sw.WriteLine(C1FlexGrid1[i, 0]);
                            sw.WriteLine(C1FlexGrid1[i, 1]);
                            sw.WriteLine(C1FlexGrid1[i, 2]);
                            sw.WriteLine(C1FlexGrid1[i, 3]);
                        }
                        sw.Close();
                        duzenlenmisDosya(tsrm_file.Text);
                        DirectoryInfo pth = new DirectoryInfo(path);
                        //klasordeki tum dosyalar okunuyor
                        tsrm_file.Properties.Items.Clear();
                        foreach (FileInfo fName in pth.GetFiles())
                        {
                            if (!string.IsNullOrEmpty(tasarimIsmi(fName.Name)))
                            {
                                tsrm_file.Properties.Items.Add(tasarimIsmi(fName.Name));
                            }
                        }
                        MessageBox.Show("Kayıt Edildi");
                    }
                }
            }
        }

        private void duzenlenmisDosya(string dosyaAdi)
        {
            DataTable ustdt = new DataTable();
            ustdt.Columns.Add("Alanlar", typeof(string));
            ustdt.Columns.Add("Sütun", typeof(int));
            ustdt.Columns.Add("Satır", typeof(int));
            ustdt.Columns.Add("Uzunluk", typeof(string));
            DataTable hareketdt = new DataTable();
            hareketdt.Columns.Add("Alanlar", typeof(string));
            hareketdt.Columns.Add("Sütun", typeof(int));
            hareketdt.Columns.Add("Satır", typeof(int));
            hareketdt.Columns.Add("Uzunluk", typeof(string));
            DataTable altdt = new DataTable();
            altdt.Columns.Add("Alanlar", typeof(string));
            altdt.Columns.Add("Sütun", typeof(int));
            altdt.Columns.Add("Satır", typeof(string));
            altdt.Columns.Add("Uzunluk", typeof(string));
            string[] newRow = new string[4];
            //ust satırlar yazılıyor
            for (int i = 5; i <= 29; i++)
            {
                if (!string.IsNullOrEmpty(C1FlexGrid1[i, 0].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 1].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 2].ToString()) & C1FlexGrid1[i, 3] != null && !string.IsNullOrEmpty(C1FlexGrid1[i, 3].ToString()))
                {
                    newRow[0] = C1FlexGrid1[i, 0].ToString();
                    newRow[1] = C1FlexGrid1[i, 1].ToString();
                    newRow[2] = C1FlexGrid1[i, 2].ToString();
                    newRow[3] = C1FlexGrid1[i, 3].ToString();
                    ustdt.Rows.Add(newRow);
                }
            }
            //hareket satırları yazılıyor
            for (int i = 30; i <= 46; i++)
            {
                if (!string.IsNullOrEmpty(C1FlexGrid1[i, 0].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 1].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 2].ToString()) & C1FlexGrid1[i, 3] != null && !string.IsNullOrEmpty(C1FlexGrid1[i, 3].ToString()))
                {
                    newRow[0] = C1FlexGrid1[i, 0].ToString();
                    newRow[1] = C1FlexGrid1[i, 1].ToString();
                    newRow[2] = C1FlexGrid1[i, 2].ToString();
                    newRow[3] = C1FlexGrid1[i, 3].ToString();
                    hareketdt.Rows.Add(newRow);
                }
            }
            //alt toplamlar yazılıyor
            for (int i = 47; i <= 66; i++)
            {
                if (i == 53)
                {
                    if (!string.IsNullOrEmpty(C1FlexGrid1[i, 0].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 1].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 2].ToString()))
                    {
                        newRow[0] = C1FlexGrid1[i, 0].ToString();
                        newRow[1] = C1FlexGrid1[i, 1].ToString();
                        newRow[2] = C1FlexGrid1[i, 2].ToString();
                        newRow[3] = " ";
                        altdt.Rows.Add(newRow);
                    }
                }
                else if (i == 50)
                {
                    if (!string.IsNullOrEmpty(C1FlexGrid1[i, 0].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 1].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 2].ToString()))
                    {
                        int satir = 0;
                        if (C1FlexGrid1[i, 2].ToString().Contains("A"))
                        {
                            int index = C1FlexGrid1[i, 2].ToString().IndexOf("A");
                            satir = int.Parse(Strings.Mid(C1FlexGrid1[i, 2].ToString(), index + 2));
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = "A" + satir;
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = "A" + satir + 1;
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = "A" + satir + 2;
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = "A" + satir + 3;
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = "A" + satir + 4;
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                        }
                        else
                        {
                            satir = int.Parse(C1FlexGrid1[i, 2].ToString());
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = satir.ToString();
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = (satir + 1).ToString();
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = (satir + 2).ToString();
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = (satir + 3).ToString();
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                            newRow[0] = C1FlexGrid1[i, 0].ToString();
                            newRow[1] = C1FlexGrid1[i, 1].ToString();
                            newRow[2] = (satir + 4).ToString();
                            newRow[3] = " ";
                            altdt.Rows.Add(newRow);
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(C1FlexGrid1[i, 0].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 1].ToString()) & !string.IsNullOrEmpty(C1FlexGrid1[i, 2].ToString()) & C1FlexGrid1[i, 3] != null && !string.IsNullOrEmpty(C1FlexGrid1[i, 3].ToString()))
                    {
                        newRow[0] = C1FlexGrid1[i, 0].ToString();
                        newRow[1] = C1FlexGrid1[i, 1].ToString();
                        newRow[2] = C1FlexGrid1[i, 2].ToString();
                        newRow[3] = C1FlexGrid1[i, 3].ToString();
                        altdt.Rows.Add(newRow);
                    }
                }
            }
            DataView altYazimDw = new DataView(altdt);
            DataView ustYazimDw = new DataView(ustdt);
            DataView hareketDw = new DataView(hareketdt);
            ustYazimDw.Sort = "Satır ASC, Sütun ASC";
            altYazimDw.Sort = "Satır ASC, Sütun ASC";
            hareketDw.Sort = "Satır ASC, Sütun ASC";
            DataTable temp1 = ustYazimDw.ToTable();
            DataTable temp2 = hareketDw.ToTable();
            DataTable temp3 = altYazimDw.ToTable();
            StreamWriter sw = new StreamWriter(path + "\\" + tsrm_file.Text + ".sbln", false);
            for (int i = 1; i <= 4; i++)
            {
                if (i != 3)
                {
                    sw.WriteLine(C1FlexGrid1[i, 1].ToString());
                }
            }
            sw.Close();
            StreamWriter sw2 = new StreamWriter(path + "\\" + tsrm_file.Text + ".trm", false);
            sw2.WriteLine("GENEL BILGI");
            for (int i = 1; i <= 4; i++)
            {
                sw2.WriteLine(C1FlexGrid1[i, 1].ToString());
            }
            sw2.WriteLine("UST BILGI");
            for (int i = 0; i <= temp1.Rows.Count - 1; i++)
            {
                sw2.WriteLine(temp1.Rows[i][0]);
                sw2.WriteLine(temp1.Rows[i][1]);
                sw2.WriteLine(temp1.Rows[i][2]);
                sw2.WriteLine(temp1.Rows[i][3]);
            }
            sw2.WriteLine("HAREKET BILGI");
            for (int i = 0; i <= temp2.Rows.Count - 1; i++)
            {
                sw2.WriteLine(temp2.Rows[i][0]);
                sw2.WriteLine(temp2.Rows[i][1]);
                sw2.WriteLine(temp2.Rows[i][2]);
                sw2.WriteLine(temp2.Rows[i][3]);
            }
            sw2.WriteLine("ALT BILGI");
            for (int i = 0; i <= temp3.Rows.Count - 1; i++)
            {
                sw2.WriteLine(temp3.Rows[i][0]);
                sw2.WriteLine(temp3.Rows[i][1]);
                sw2.WriteLine(temp3.Rows[i][2]);
                sw2.WriteLine(temp3.Rows[i][3]);
            }

            sw2.Close();
        }

        private void btn_gonder_Click(object sender, EventArgs e)
        {

            {
                if (!string.IsNullOrEmpty(tsrm_file.Text))
                {
                    if (File.Exists(path + "\\" + tsrm_file.Text + ".tsrm"))
                    {
                        Rapi oRAPI = new Rapi();
                        dlg = new DevExpress.Utils.WaitDialogForm("Dosya Aktarılıyor !", "Lütfen Bekleyiniz...");
                        if (oRAPI.copyFileToTerminal(path + "\\" + tsrm_file.Text + ".trm", "\\My Documents\\" + tsrm_file.Text + ".tsrm"))
                        {
                            if (oRAPI.copyFileToTerminal(path + "\\" + tsrm_file.Text + ".sbln", "\\My Documents\\" + tsrm_file.Text + ".sbln"))
                            {
                                dlg.Close();
                                MessageBox.Show("Dosya Aktarım İşlemi Tamamlandı.");
                            }
                            else
                            {
                                dlg.Close();
                                MessageBox.Show("Dosya Aktarılamadı.");
                            }
                        }
                        else
                        {
                            dlg.Close();
                            MessageBox.Show("Dosya Aktarılamadı.");
                        }
                    }
                }
            }
        }

        private void C1FlexGrid1_AfterEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
        {
            {
                if (C1FlexGrid1.Row >= 30 & C1FlexGrid1.Row <= 41)
                {
                    if (C1FlexGrid1.Col == 2)
                    {
                        if (Convert.ToInt32(C1FlexGrid1[C1FlexGrid1.Row, C1FlexGrid1.Col]) > 0)
                        {
                            int x = Convert.ToInt32(C1FlexGrid1[C1FlexGrid1.Row, C1FlexGrid1.Col]);
                            for (int i = 30; i <= 46; i++)
                            {
                                C1FlexGrid1[i, 2] = x;
                            }
                        }
                        else if (Convert.ToInt32(C1FlexGrid1[C1FlexGrid1.Row, C1FlexGrid1.Col]) <= 0)
                        {
                            if (C1FlexGrid1.Row == 46)
                            {
                                C1FlexGrid1[C1FlexGrid1.Row, C1FlexGrid1.Col] = C1FlexGrid1[C1FlexGrid1.Row - 1, C1FlexGrid1.Col];
                            }
                            else
                            {
                                C1FlexGrid1[C1FlexGrid1.Row, C1FlexGrid1.Col] = C1FlexGrid1[C1FlexGrid1.Row + 1, C1FlexGrid1.Col];
                            }
                        }
                    }
                }
            }
        }

        private void tsrm_file_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tsrm_file.Text) & tsrm_file.SelectedIndex >= 0)
            {
                string fpath = path + "\\" + tsrm_file.Text + ".tsrm";
                yeniTasarim(fpath);
            }
        }

        private void btn_sablon_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tsrm_file.Text))
            {
                if (File.Exists(path + "\\" + tsrm_file.Text + ".sbln"))
                {
                    PrintDocument1.Print();
                }
                else
                {
                    MessageBox.Show("Aradığınız Şablon Dosyası Mevcut Değil");
                }
            }
        }

        private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            string yaziciPortu = "";
            int satirSayisi = 0;
            int hareketGenisligi = 0;
            StreamReader sr = new StreamReader(path + "\\" + tsrm_file.Text + ".sbln");
            yaziciPortu = sr.ReadLine();
            satirSayisi = int.Parse(sr.ReadLine());
            hareketGenisligi = int.Parse(sr.ReadLine());
            string line = "";
            int x = -1;
            int j = 0;
            for (int i = 1; i <= satirSayisi; i++)
            {
                line = i.ToString();
                if (i >= 10)
                {
                    for (j = 3; j <= hareketGenisligi; j++)
                    {
                        if (x == -1)
                        {
                            x = 3;
                        }
                        line = line + x;
                        x = x + 1;
                        if (x == 10)
                        {
                            x = 0;
                        }
                    }
                }
                else
                {
                    for (j = 2; j <= hareketGenisligi; j++)
                    {
                        if (x == -1)
                        {
                            x = 2;
                        }
                        line = line + x;
                        x = x + 1;
                        if (x == 10)
                        {
                            x = 0;
                        }
                    }
                }
                e.Graphics.DrawString(line, new Font("Microsoft Sans Serif", 13, FontStyle.Regular), Brushes.Black, 5, (i + 1) * 17);
                line = "";
                x = -1;
                j = 0;
            }
        }
    }
}
